/**
 * @author digitalspaghetti
 */
(function($) {
$.fn.toFeed = function(options) {
   return this.each(function() {
       var opts = jQuery.extend({
           url:  this.href,
           max:  5
       }, options || {});

       var $this = $(this);
       var feed = new google.feeds.Feed(opts.url);
       feed.load(function(result) {
           if (!result.error) {
               var max = Math.min(result.feed.entries.length, opts.max);
               var f = $('<div class="feed"></div>');
               f.append('<h1 class="feed">'+result.feed.title+'</h1>');
               for (var i = 0; i < max; i++) {
                   var entry = result.feed.entries[i];
                   var title = entry.title;
                   var snip  = entry.contentSnippet;
                   var link  = entry.link;
                   var date  = entry.publishedDate;

                   f.append('<h2 class="feeditem"><a href="'+link+'">'+title+'</a></h2>')
                       .append('<div class="feeddate">'+date+'</div>')
                       .append('<div class="feedsnip">'+snip+'</div> ');
               }
               $this.after(f).remove();
           }
       });
   });
};
})(jQuery);